package pi.client.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.image.BufferedImage;

import javax.swing.JPanel;

import pi.client.core.MyProgram;
import pi.client.utils.ImageUtils;

@SuppressWarnings("serial")
public abstract class MyPanelBase extends JPanel{
	protected MyMainPanel mainPanel;
	private BufferedImage backgroundImage;
	public int width;
	public int height;
	
	public MyPanelBase(MyMainPanel mainPanel, String backgroundFilename, int width, int height){
		super(true);
		this.mainPanel = mainPanel;
		this.width = width;
		this.height = height;
		
		setLocation(0, 0);
		setPreferredSize(new Dimension(width, height));
		if(backgroundFilename!="")
			backgroundImage = ImageUtils.LoadImage(backgroundFilename);
	}

	@Override public void paintComponent(Graphics g){
		Draw(g);
	}

	protected void Draw(Graphics g){
		g.drawImage(backgroundImage, 0, 0, MyProgram.ScreenWidth, MyProgram.ScreenHeight, null);		
	}
	
	protected void DrawTitle(Graphics g, String text){
		FontMetrics fm = g.getFontMetrics();
		int stringWidth = fm.stringWidth(text);
		int stringHeight = fm.getHeight();
		
		g.setColor(Color.white);
		g.drawString(text, width/2 - stringWidth/2, height/2 - stringHeight/2);
	}
	
	protected void DrawTitle(Graphics g, String text, int x, int y){
		FontMetrics fm = g.getFontMetrics();
		int stringWidth = fm.stringWidth(text);
		int stringHeight = fm.getHeight();
		
		g.setColor(Color.white);
		g.drawString(text, x - stringWidth/2, y - stringHeight/2);
	}
	
	protected void KeyPressedEvent(KeyEvent e){}
	protected void KeyReleasedEvent(KeyEvent e){}
	protected void KeyTypedEvent(KeyEvent e){}

	protected void MouseDraggedEvent(MouseEvent e){}
	protected void MouseMovedEvent(MouseEvent e){}

	protected void MouseClickedEvent(MouseEvent e){}
	protected void MouseEnteredEvent(MouseEvent e){}
	protected void MouseExitedEvent(MouseEvent e){}
	protected void MousePressedEvent(MouseEvent e){}
	protected void MouseReleasedEvent(MouseEvent e){}
	
	protected void MouseWheelMovedEvent(MouseWheelEvent e){}
}